package com.learn.observer.generic;

import com.learn.observer.WeatherType;
import lombok.extern.slf4j.Slf4j;

/**
 * <p>项目名称: design-pattern </p>
 * <p>文件名称: GWeather </p>
 * <p>描述: TODO </p>
 *
 * @author zhousiqi
 * @version v0.0.1
 * @since 2018/10/18 17:30
 */
@Slf4j
public class GWeather extends Observable<GWeather, Media, WeatherType> {

    private WeatherType currentWeather;
    private String detail;

    public GWeather(String detail) {
        this.detail = detail;
        currentWeather = WeatherType.SUNNY;
    }

    /**
     * Makes time pass for weather
     */
    public void timePasses() {
        WeatherType[] enumValues = WeatherType.values();
        currentWeather = enumValues[(currentWeather.ordinal() + 1) % enumValues.length];
        log.info("The weather of {} changed to {}.", detail, currentWeather);
        notifyObservers(currentWeather);
    }

    public String getDetail() {
        return detail;
    }
}
